<?php
namespace app\admin\model;
use think\Model;

Class Numbr extends Model
{
    protected $pk = 'n_id';
    protected $table ='lou_number';
    public function index()
    {
        $re = self::paginate(8);
        return $re;
    }
    public function add()
    {
        $re=  new Numbr();
        $data=input('param.');
        $result = $re->save($data);
        return $result;
    }
    public function adds()
    {
        $stu = new Numbr();
        $file = $this->upload('n_photo');
        $data = [
            'n_name' => input("param.n_name"),
            'n_address' => input("param.n_address"),
            'n_photo' => $file,
        ];
        $request = $stu->save($data);
        return $request;
    }
    public function edit()
    {
        $stu = new Numbr();
        $id = input('param.n_id');
        //halt($id);
        $data = input('param.');
        $request = $stu->allowField(true)->save($data,['n_id'=>$id]);
        return $request;
    }
    public function edits()
    {
        $stu = new Numbr();
        $file = $this->upload('n_photo');
        $id = input('param.n_id');

        $data = [
            'n_name' => input("param.n_name"),
            'n_address' => input("param.n_address"),
            'n_photo' => $file,
        ];
        //halt($data);
        $request = $stu->allowField(true)->save($data,['n_id'=>$id]);
        return $request;
    }
    public function del()
    {
        $stu = new Numbr();
        $id=input('param.n_id');
        //halt($id);
        $request = $stu->destroy($id);
        return $request;
    }
    public function upload($fileName){
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file($fileName);
        // 当前目录指的是入口文件（index.php)所在的目录
        $info = $file->move( 'uploads');
        return $info->getSaveName();
    }

}
?>